<?php
/**
 * 系统模型逻辑层
 * @author maniac
 */
namespace app\common\logic;

class Mods extends Base
{
    /**
     * 重组提交信息
     * @param  array $data 请求的信息
     */
    public function recombine($data)
    {
        if (isset($data['ids']) && !empty($data['ids'])) {
            // 字段名 field
            foreach ($data['ids'] as $k => $v) {
                if (!trim($data['fname'][$k])) {
                    exception('请输入所有的字段名称');
                }
                $data['field'][$v] = $data['fname'][$k];
            }
            
            // 列表显示项
            $list_field = [];
            if (isset($data['list_field']) && $data['list_field']) {
                foreach ($data['list_field'] as $k => $v) {
                    if ($v) {
                        $list_field[] = $data['ids'][$k];
                    }
                }
            }
            
            // 前台录入项
            $qenter = [];
            if (isset($data['qenter']) && !empty($data['qenter'])) {
                foreach ($data['qenter'] as $k => $v) {
                    if ($v) {
                        $qenter[] = $data['ids'][$k];
                    }
                }
            }
            
            // 前台必填项
            $qmust_enter = [];
            if (isset($data['qmust_enter']) && !empty($data['qmust_enter'])) {
                foreach ($data['qmust_enter'] as $k => $v) {
                    if ($v) {
                        $qmust_enter[] = $data['ids'][$k];
                    }
                }
            }
            
            // 后台录入项
            $henter = [];
            if (isset($data['henter']) && !empty($data['henter'])) {
                foreach ($data['henter'] as $k => $v) {
                    if ($v) {
                        $henter[] = $data['ids'][$k];
                    }
                }
            }
            
            // 后台必填项
            $hmust_enter = [];
            if (isset($data['hmust_enter']) && !empty($data['hmust_enter'])) {
                foreach ($data['hmust_enter'] as $k => $v) {
                    if ($v) {
                        $hmust_enter[] = $data['ids'][$k];
                    }
                }
            }
            
            $data['field']       = serialize($data['field']);
            $data['list_field']  = serialize($list_field);
            $data['qenter']      = serialize($qenter);
            $data['qmust_enter'] = serialize($qmust_enter);
            $data['henter']      = serialize($henter);
            $data['hmust_enter'] = serialize($hmust_enter);
            unset($data['ids'], $data['f'], $data['fname']);
        }
        return $data;
    }
}
